import pymysql
class Databasefunction(object):
    def __init__(self,host="localhost",user='root',password='123123',database='woniuatm' charset="utf8",port=3306, autocommit=True,autocommit=True):
        self.connection = pymysql.connect(host=host, user=user, password=password, database=database, charset=charset,port=port, autocommit=autocommit)

    def update(self, sql):
        self.cursor = self.connection.cursor()
        try:
            self.cursor.execute(sql)
        except:
            self.connection.rollback()
        finally:
            self.cursor.close()

    def select(self, sql):
        self.cursor = self.connection.cursor()
        try:
            self.cursor.execute(sql)
            result = cursor.fetchall()
            return result
        except:
            print("Error:查询数据库失败!")
        finally:
            self.cursor.close()
        #del lst[i]

    def __del__(self):
        self.connection.close()

